package artid.com.arttogo.adapter;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import com.bumptech.glide.Glide;
import java.util.List;
import artid.com.arttogo.R;
import artid.com.arttogo.bean.RecomAuctionListParser;
import artid.com.arttogo.utils.MyBitmapImageViewTarget;
import artid.com.arttogo.utils.NetUtils;
import artid.com.arttogo.view.DynamicHeightImageView;

/**
 * 
*    
* 项目名称：ArtworkArt   
* 类名称：RecentAuction_Adapter   
* 类描述：拍卖行-近期拍卖适配器   
* 创建人：耿卫斌   
* 创建时间：2017-3-1 下午1:26:39   
*
 */
public class RecentAuction_Adapter extends BaseAdapter {
	private Context mContext;
	private List<RecomAuctionListParser> list;

	public RecentAuction_Adapter(Context mContext,
								 List<RecomAuctionListParser> list) {
		super();
		this.mContext = mContext;
		this.list = list;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return list.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return list.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(final int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		ViewHolder holder = null;
		View v = convertView;
		if (v == null) {
			holder = new ViewHolder();
			v = LayoutInflater.from(mContext).inflate(R.layout.item_recentauction, null);
			holder.img=(DynamicHeightImageView) v.findViewById(R.id.itemRecentauction_img);
			holder.state=(TextView) v.findViewById(R.id.itemRecentauction_state);
			holder.title=(TextView) v.findViewById(R.id.itemRecentauction_title);
			holder.time=(TextView) v.findViewById(R.id.itemRecentauction_time);
			holder.num=(TextView) v.findViewById(R.id.itemRecentauction_num);
			holder.address=(TextView) v.findViewById(R.id.itemRecentauction_address);
			v.setTag(holder);
		} else {
			holder = (ViewHolder) v.getTag();
		}
        holder.img.isRightAngle=true;
		holder.img.setHeight(list.get(position).getHeight());
		Glide.with(mContext).load(list.get(position).getImgurl()
				+ "_"+ (Integer.parseInt(NetUtils.getDisplayMetrics((Activity)mContext).get(NetUtils.DM_WIDTH)) /2) + "x10.png"
				).asBitmap().centerCrop()
		.placeholder(R.drawable.ic_menu_rotate).error(R.drawable.ic_menu_rotate)
		.into(new MyBitmapImageViewTarget(holder.img));
		holder.title.setText(list.get(position).getTitle());
		int status=list.get(position).getStatus();
		switch (status) {
		case 0:
			holder.state.setText("已结束");
			holder.address.setText("拍卖地点："+list.get(position).getAddress());
			holder.time.setText("拍卖时间："+list.get(position).getAuction_start_time()+"-"+list.get(position).getAuction_end_time());
			break;
		case 1:
			holder.state.setText("待预展");
			holder.address.setText("预展地点："+list.get(position).getAddress());
			holder.time.setText("预展时间："+list.get(position).getPreview_start_time()+"-"+list.get(position).getPreview_end_time());
			break;
		case 2:
			holder.state.setText("预展中");
			holder.address.setText("预展地点："+list.get(position).getAddress());
			holder.time.setText("预展时间："+list.get(position).getPreview_start_time()+"-"+list.get(position).getPreview_end_time());
			break;
		case 3:
			holder.state.setText("拍卖中");
			holder.address.setText("拍卖地点："+list.get(position).getAddress());
			holder.time.setText("拍卖时间："+list.get(position).getAuction_start_time()+"-"+list.get(position).getAuction_end_time());
			break;

		default:
			break;
		}
		holder.num.setText("共"+list.get(position).getSpecial_num()+"个专场");
		return v;
	}
	class ViewHolder {
		DynamicHeightImageView img;
		TextView state,title,time,num,address;
	}
}
